package org.lessnote.server.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.lboot.core.domain.ResponseDTO;
import org.lboot.core.exception.BusinessException;
import org.lboot.s3.client.S3Client;
import org.lessnote.server.service.NoteCtl;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("note")
@Api(tags = "目录管理")
@AllArgsConstructor
public class NoteDirController {
    S3Client s3Client;

    NoteCtl noteCtl;

    @PostMapping("dirs")
    @ApiOperation(value = "新建目录")
    public ResponseDTO<Object> dirCreate(@RequestParam("path") String path){
        if (path.startsWith("/")){
            throw new BusinessException(HttpStatus.BAD_REQUEST,"不可以使用 / 开头");
        }
        return ResponseDTO.succData(
                noteCtl.mkdir(path)
        );
    }

    @GetMapping("dirs")
    @ApiOperation(value = "目录索引")
    public ResponseDTO<Object> dirIndex(){
        return ResponseDTO.succData(
                noteCtl.getDirs()
        );
    }
}
